package net.boar.os;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @Author: zgl
 * @Date: 2021/6/23 11:03
 * @Description:
 */
public class OperatingSystemDay02 {
    private FloppyDiskEntity floppyDisk = new FloppyDiskEntity();
    private void writeToFloppy(String fineName){
        File file = new File(fineName);
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            byte[] buf = new byte[512];
            buf[510] = 0x55;
            buf[511] = (byte) 0xaa;
            if(in.read(buf) != -1){
                //0面,0柱,2,区
                floppyDisk.writeFloppy(0,0,1,buf);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public OperatingSystemDay02(String s){
        writeToFloppy(s);
    }
    public void makeFloppy(){
        String s = "xadaswqxxxx------xxxxxxxxxxxx--------xxxxxxxxx";
        //0面,1柱,2,区
        floppyDisk.writeFloppy(0,1,2,s.getBytes());
        floppyDisk.makeFloppy(getPath() + "mgos02.img");
    }

    public static void main(String[] args) {
        //nasm -o boot.bat boot.asm
        wrapper();
        OperatingSystemDay02 op = new OperatingSystemDay02(getPath() + "boot.bat");
        op.makeFloppy();
    }
    private static void wrapper(){
        WorkerEntity entity = new WorkerEntity();
        entity.setCmd("nasm -o boot.bat boot.asm");
        entity.setWorkerPath(getPath());
        entity.setCreateBarName("build.bat");
        entity.setEncoding("GBK");
        Build.builder(entity);
    }
    private static String getPath(){
        return "D:\\project\\MgOS\\code02\\";
    }
}
